﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Tesla.DataAccess.DataAccessComponents;
using Tesla.Service.DataContracts;
using Tesla.DataAccess.DataAccessLogic;
using Tesla.Util.Utilities;
using Tesla.DataAccess.DataAccessLogic.Implementations;

namespace Tesla.DataAccess.LinqHost
{
    class Program
    {
        static void Main(string[] args)
        {

            //ThemeDA daTheme = new ThemeDA();
            //BaseDC[] tDCs = daTheme.Read().ToArray();

            #region Commented
            //BaseOperationalDA daBase = DAFactory.CreateInstance(1);
            //ThemeDC tDC = new ThemeDC();
            //tDC.ThemeId = Guid.NewGuid();
            //tDC.ThemeName = "Tom";
            //tDC.ThemeMandatory = true;
            //tDC.ThemeHidden = true;
            //tDC.VisibilityFrom = DateTime.Now;
            //tDC.VisibilityTo = DateTime.Now;
            //tDC.UpdatedBy = Guid.NewGuid();
            //tDC = (ThemeDC)daTheme.Create(tDC as BaseDC);
            
            
            ////Invoker - Business Service Code

            ////BaseOperationalDA daBase = DAFactory.CreateInstance(1);
            //EmployeeDA daEmployee = daBase as EmployeeDA;

            //EmployeeDC eDC = new EmployeeDC();
            //eDC.EmpID= Guid.NewGuid();
            //eDC.FirstName= "Tom";
            //eDC.LastName= "Kramer";
            //eDC.RoleId= new Guid("8BA3841A-DFDD-40D8-A8D2-C1F329A7D976");
            //eDC.SiteId = new Guid("D4520A10-795A-4584-B47F-8910BBC62EE6");
            //daEmployee.Create(eDC as BaseDC);
            ////Invoker - Business Service Code
            
            
            ////Data retrieval joins
            //using ( EmployeeDataContext context = new EmployeeDataContext())
            //{
            //    //IEnumerable<Site> siteCollection = from s in context.Sites select s;
            //    //IEnumerable<Role> rolesCollection = from r in context.Roles select r;


            //    var query = from e in context.Employees
            //                join r in context.Roles on e.Employee_RoleId equals r.RoleId
            //                join s in context.Sites on e.Employee_SiteId equals s.SiteId
            //                where r.RoleDescription.Trim().ToUpper() =="DEVELOPER"
            //                select new
            //                   {
            //                       _firstName = e.EmployeeFirstName,
            //                       _lastName = e.EmployeeLastName,
            //                       _roleName = r.RoleDescription,
            //                       _siteName = s.SiteName
            //                   };
            //    EmployeeDC empOBJ = new EmployeeDC();
            //    IList<EmployeeDC> listEmployeeDC = null;
            //    listEmployeeDC = new List<EmployeeDC>(); 
            //    foreach (var emp in query)
            //    {
            //        empOBJ.FirstName = emp._firstName;
            //        empOBJ.LastName = emp._lastName;
            //        empOBJ.RoleName = emp._roleName;
            //        empOBJ.SiteName = emp._siteName;
            //        listEmployeeDC.Add(empOBJ);
            //    }

            //    //Conversion to Base DC of Ilist EntityDC
            //    IList<BaseDC> genericBase = listEmployeeDC.Cast<BaseDC>().ToList();
            //    foreach (BaseDC bDC in genericBase)
            //    {
            //        bDC.UpdateState = 0;
            //        bDC.UpdatedBy = "ME";
            //        bDC.UpdateDate = System.DateTime.Now;
            //    }
            //}

            //Employee e1 = new Employee();
            //e1.EmployeeId = Guid.NewGuid();
            //e1.EmployeeFirstName = "Tom";
            //e1.EmployeeLastName = "Kramer";
            //e1.Employee_RoleId = new Guid("8BA3841A-DFDD-40D8-A8D2-C1F329A7D976");
            //e1.Employee_SiteId = new Guid("D4520A10-795A-4584-B47F-8910BBC62EE6");
            //e1.UpdateCount = 0;
            //e1.UpdatedBy = "myself";
            //e1.UpdateTimeStamp = System.DateTime.Now;

            ////Data insert
            //using (EmployeeDataContext context = new EmployeeDataContext())
            //{
            //    context.DeferredLoadingEnabled = false;
            //    context.Employees.InsertOnSubmit(e1);
            //    context.SubmitChanges();
            //}
            #endregion
        }    
    }
}
